<template>
  <!--培训经历-->
  <view>
    <myHead
      :title="title"
      :right="true"
      text_right="保存"
      @clickRight="clickRight"
    ></myHead>
    <view class="conten">
      <view class="li-box fl-lr-c">
        <view class="name">培训机构</view>
        <view>
          <input
            placeholder-class="input_pal"
            type="text"
            v-model="CompanyName"
            placeholder="请输入"
          />
        </view>
      </view>

      <view class="li-box fl-lr-c">
        <view class="name">培训课程</view>
        <view>
          <input
            placeholder-class="input_pal"
            type="text"
            v-model="CourseName"
            placeholder="请输入"
          />
        </view>
      </view>

      <u-datetime-picker
        v-if="show1"
        :show="show1"
        v-model="value1"
        mode="year-month"
        title="请选择开始时间"
        closeOnClickOverlay
        @close="show1 = false"
        :minDate="minDate"
        :maxDate="maxDate"
        @cancel="show1 = false"
        @confirm="changeDirthDate"
      ></u-datetime-picker>

      <u-datetime-picker
        v-if="show2"
        :show="show2"
        v-model="value2"
        mode="year-month"
        title="请选择结束时间"
        closeOnClickOverlay
        @close="show2 = false"
        :minDate="minDate2"
        :maxDate="maxDate"
        @cancel="show2 = false"
        @confirm="changeDirthDate"
      ></u-datetime-picker>

      <view class="li-box fl-lr-c">
        <view class="name">培训时间</view>
        <view class="fl-t">
          <view class="content fl-t">
            <text @click="linJob(1)">
              <text v-if="StartDate">{{ StartDate | formatDateYM }}</text>
              <text v-else>开始时间</text>
            </text>
            <view class="connect">-</view
            ><text @click="linJob(2)">
              <text v-if="EndDate">{{ EndDate | formatDateYM }}</text>
              <text v-else>结束时间</text>
            </text>
          </view>
          <u-icon name="arrow-right"></u-icon>
        </view>
      </view>
      <!-- <view class="li-box  fl-lr-c">
				<view class="name">培训内容</view>
				<view>
					<input placeholder-class="input_pal" type="text" v-model="Content" placeholder="请输入" />
				</view>
			</view> -->
    </view>
    <bottomBut @bottomBut="bottomBut" v-if="type == 2"></bottomBut>
  </view>
</template>

<script>
import myHead from "@/pages/component/baseHead.vue";
import bottomBut from "@/pages/component/bottomBut.vue";
import {
  atPresentTime,
  specifyBeforeVX,
  atPresentTimeX,
  TimeString,
} from "@/utils/Time";
export default {
  data() {
    return {
      title: "培训经历",
      type: 0, //1add  2编辑
      show1: false,
      show2: false,
      dateType: 1,
      StartDate: "",
      EndDate: "",
      CompanyName: "", //培训公司名称
      CourseName: "", //培训课程名称
      //   Content: "",
      // 当前id
      Id: 0,
      // 父id
      fuid: 0,
      minDate: 0,
      maxDate: 0,
      value1: "",
      value2: "",
    };
  },
  //子组件
  components: {
    myHead,
    bottomBut,
  },
  onLoad(o) {
    this.minDate = atPresentTimeX(60);
    this.maxDate = atPresentTime();
    this.type = o.type;
    this.fuid = o.fuid;
    if (this.type == 2) {
      let data = JSON.parse(o.data);
      this.Id = data.Id;
      this.CompanyName = data.CompanyName;
      this.CourseName = data.CourseName;
      this.StartDate = data.StartDate.split(" ")[0];
      this.EndDate = data.EndDate.split(" ")[0];
      //   this.Content = data.Content;
    }
  },
  // 计算方法
  methods: {
    linJob(type) {
      this.dateType = type;
      if (type == 1) {
        this.value1 = this.StartDate
          ? this.StartDate
          : TimeString(this.maxDate);
        this.show1 = true;
      } else {
        this.value2 = this.EndDate ? this.EndDate : TimeString(this.maxDate);
        this.show2 = true;
      }
    },
    changeDirthDate(e) {
      const timeFormat = uni.$u.timeFormat;
      let ds = timeFormat(e.value, "yyyy-mm-dd");
      if (this.dateType == 1) {
        //开始
        if (this.EndDate) {
          if (ds > this.EndDate) {
            this.$util.toast("开始时间不能高于低于时间");
            return;
          }
        }
        this.StartDate = ds;
      } else {
        if (this.StartDate) {
          if (ds < this.StartDate) {
            this.$util.toast("结束时间不能低于开始时间");
            return;
          }
        }
        this.EndDate = ds;
      }
      this.show1 = false;
      this.show2 = false;
    },
    clickRight() {
      if (!this.CompanyName) {
        this.$util.toast("请输入培训机构");
        return;
      }
      if (!this.CourseName) {
        this.$util.toast("请输入机构课程");
        return;
      }
      if (!this.StartDate) {
        this.$util.toast("请选择培训开始时间");
        return;
      }
      if (!this.EndDate) {
        this.$util.toast("请选择培训结束时间");
        return;
      }

      if (this.type == 2) {
        //编辑修改
        this.$http.huirc
          .trainexpup({
            Id: this.Id,
            ResumeId: this.fuid,
            CompanyName: this.CompanyName,
            CourseName: this.CourseName,
            StartDate: this.StartDate,
            EndDate: this.EndDate,
            //   Content: this.Content,
            SortCode: 0,
          })
          .then((res) => {
            if (res.Success) {
              this.$util.toast("保存成功");
              setTimeout(() => {
                uni.navigateBack();
              }, 1600);
            }
          });
      } else {
        this.$http.huirc
          .trainexpcr({
            ResumeId: this.fuid,
            CompanyName: this.CompanyName,
            CourseName: this.CourseName,
            StartDate: this.StartDate,
            EndDate: this.EndDate,
            // Content: this.Content,
            SortCode: 0,
          })
          .then((res) => {
            if (res.Success) {
              this.$util.toast("保存成功");
              setTimeout(() => {
                uni.navigateBack();
              }, 1600);
            }
          });
      }
    },
    bottomBut() {
      let that = this;
      uni.showModal({
        title: "删除提示",
        content: "确认要删除这条数据",
        success: function (res) {
          if (res.confirm) {
            let data = {
              Id: that.Id,
            };
            that.$http.huirc.trainexpdel(data).then((res) => {
              if (res.Success) {
                that.$util.toast("删除成功");
                setTimeout(() => {
                  uni.navigateBack();
                }, 1000);
              }
            });
          }
        },
      });
    },
  },
  computed: {
    minDate2() {
      if (this.startTime) {
        return specifyBeforeVX(this.startTime, 0);
      } else {
        return this.minDate;
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.li-box {
  background-color: #fff;
  .name {
    font-size: 30rpx;
    font-family: PingFang SC;
    font-weight: bold;
    color: #000000;
    flex-shrink: 0;
  }

  .logo {
    width: 106rpx;
    height: 106rpx;
    border-radius: 50%;
  }

  .input_pal,
  input,
  .content {
    font-size: 30rpx;
    font-family: PingFang SC;
    font-weight: 500;
    color: #999999;
    text-align: end;

    .connect {
      padding: 0 20rpx;
      color: #000;
      font-size: 32rpx;
    }
  }

  .radio-box {
    margin-left: 50rpx;

    .radio-text {
      font-size: 30rpx;
      font-family: PingFang SC;
      font-weight: 500;
      color: #999999;
      padding-left: 20rpx;
    }
  }

  .tui-textarea {
    flex: 1;
  }
}
</style>
